<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>首页</title>
    <script src="/static/axios.min.js"></script>
</head>
<body>
现在正在进行的游戏
<button onclick="create_room()">创建房间</button>
<input type="number" id="room_id">
<button onclick="join_room()">创建房间</button>
</body>
<script>
    let cl  = sessionStorage.getItem("session_token") !== null;
    function join_room() {
        if (!cl) {
            location.href="/login";
            return
        }
        sessionStorage.setItem("room_id",document.getElementById("room_id").value);
        location.href ="/room?id="+document.getElementById("room_id").value;
    }
    function create_room() {
        if (!cl) {
            location.href="/login";
            return
        }
        axios.post("/create_room",{session_token:sessionStorage.getItem("session_token")}).then(d=>{
            alert("创建成功");
            location.href ="/room?id="+d.data;
            sessionStorage.setItem("room_id",d.data);
        }).catch(()=>{
            console.log("error");
        })
    }

</script>
</html>